namespace SharpTalk.Core.Base
{
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using Data;
    using Diagnostic;
    using Enums;
    using Interfaces;

    public abstract class ChatRoomManagerBase : Traceable, IChatRoomManager
    {
        private IChatRoomDataProvider _dataprovider;

        protected ChatRoomManagerBase(IChatRoomDataProvider dataProvider)
        {
            _dataprovider = dataProvider;
        }

        /// <summary>
        /// Obtains or defines the DataProvider
        /// </summary>
        public IChatRoomDataProvider DataProvider
        {
            get { return _dataprovider; }
            set { _dataprovider = value; }
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public virtual void Dispose()
        {
            TraceMethodCall(MethodBase.GetCurrentMethod());
            if (_dataprovider == null) return;

            _dataprovider.Dispose();
            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// 
        /// </summary>
        public void Initialize()
        {
            TraceMethodCall(MethodBase.GetCurrentMethod());
            if(_dataprovider !=null)
                _dataprovider.Initialize();
        }
        /// <summary>
        /// 
        /// </summary>
        public virtual void ClearAll()
        {
            TraceMethodCall(MethodBase.GetCurrentMethod());
            if (_dataprovider != null)
                _dataprovider.ClearAll();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public abstract bool Save(ChatRoom obj);
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public abstract List<ChatRoom> All();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public abstract ChatRoom Update(ChatRoom obj);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public abstract bool Delete(ChatRoom obj);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public abstract bool Delete(Guid guid);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public abstract ChatRoom Find(Guid guid);
        public abstract ChatRoom Create(string name, ChatRoomTypeEnum type, byte[] passwordhash,string motd, Guid owner);
        public abstract ChatRoom Find(string name);
        public abstract ChatRoom Find(string name, ChatRoomTypeEnum type);
        public abstract List<ChatRoom> Find(ChatRoomTypeEnum type);
        public abstract ChatRoomDetails Join(Guid chatroomGuid, Guid user, byte[] password);
        public abstract bool Leave(Guid chatroomGuid, Guid user);
        public abstract ChatRoom Update(ChatRoom chatRoom, bool definePassword);
    }
}